package com.kgc.easyshopping.service.impl;

import com.kgc.easyshopping.dao.ProductMapper;
import com.kgc.easyshopping.entity.Product;
import com.kgc.easyshopping.service.ProductService;
import com.kgc.easyshopping.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper pm;

    @Override
    public int deleteByPrimaryKey(Integer pid) {
        return pm.deleteByPrimaryKey(pid);
    }

    @Override
    public int insert(Product record) {
        return 0;
    }

    @Override
    public int insertSelective(Product record) {
        return 0;
    }

    @Override
    public List<Product> adminSelectByProduct(Map<String,Object> params) {
        return pm.adminSelectByProduct(params);
    }

    /**
     * 管理员页面商品分页
     * @param params
     * @return
     */
    @Override
    public PageInfo<Product> adminGetProductInfo(Map<String, Object> params) {
        PageInfo<Product> info = new PageInfo<Product>();
        int pageNow = 1;
        if (params.containsKey("pageNow")){
            pageNow = Integer.parseInt((String) params.get("pageNow"));
            params.put("pageNow",pageNow);
        }
        int pageSize = 10;
        if (params.containsKey("pageSize")){
            pageSize = Integer.parseInt((String) params.get("pageSize"));
            params.put("pageSize",pageSize);
        }
        int start = (pageNow-1)*pageSize;
        params.put("start",start);
        info.setPageNow(pageNow);
        info.setPageSize(pageSize);
        info.setData(adminSelectByProduct(params));
        info.setTotal(pm.adminProductTotal(params));
        return info;
    }

    @Override
    public Product selectByPrimaryKey(Integer pid) {
        return pm.selectByPrimaryKey(pid);
    }

    @Override
    public int updateByPrimaryKeySelective(Product record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(Product record) {
        return 0;
    }
}
